//Copyright 2012 Trevin Liberty
//GNU GPL v3
//Author: Trevin Liberty

#include "Animator.h"

void Animator::setDirection(int i) {
	if(i > 8)
		i = 3;
	direction = i;
}

void Animator::setSlide(Slide* image, float maxTime) {
	currentSlide = image;
	maxFrame = image->numSlides;
	this->maxTime = maxTime;
}

/*
Direction -
1, 2, 3, 4, 5,  6,  7,  8
N, S, E, W, NE, NW, SW, SE
*/
ALLEGRO_BITMAP* Animator::getImage() {
	maxFrame = currentSlide->numSlides;

	if(!ok) {
		if(al_get_time() - lastUpdate > maxTime) {
			curFrame++;
			lastUpdate = al_get_time();
		}

		if(curFrame >= maxFrame)
			curFrame = 0;
	}

	int x = (direction-1)*currentSlide->slideWidth;
	int y = curFrame*currentSlide->slideHeight;

	return al_create_sub_bitmap(currentSlide->image, 
		x, y, currentSlide->slideWidth, currentSlide->slideHeight);
}